package gant.ext

import org.codehaus.gant.GantBinding
import org.codehaus.gant.GantState

/**
 * Maintains a global instance to get at the binding being used by a script
 */
class AntBindingFactory {
    final GantBinding binding
    static AntBindingFactory _instance

    private AntBindingFactory(GantBinding binding) {
        GantState.metaClass.static.setLoggingLevel = {int level ->
            GantState.verbosity = level
            binding.ant.logger.messageOutputLevel = level
        }
        this.binding = binding
    }

    def static createInstance(GantBinding binding) {
        assert null == _instance: "AntBindingFactory has aleady been created"

        _instance = new AntBindingFactory(binding)
    }

    static AntBindingFactory getInstance() {
        assert null != _instance: "AntBindingFactory has not been created yet"
        return _instance
    }

    static boolean bindingFactoryExists() {
        return _instance != null
    }
}
